#pragma once

#include "../Common/Logger.hpp"
#include "Model.hpp"
#include "View.hpp"
#include <iostream>
#include <string>

namespace OJ
{
  class Controller
  {
  public:
    Controller() = default;
    ~Controller() = default;

  public:
    bool getAllQuestions(std::string &html)
    {
      std::vector<OJ::Question> questions;
      if (!_model.getAllQuestions(questions))
      {
        DLOG("Failed to get all questions");
        return false;
      }
      else
      {
        // 交给view处理
        _view.creatAllQuestionsHTML(questions, html);
        return true;
      }
    }
    bool getQuestion(int id, std::string &html)
    {
      OJ::Question question;
      if (!_model.getQuestion(id, question))
      {
        DLOG("Failed to get question");
        return false;
      }
      else
      {
        // 交给view处理
        _view.creatQuestionHTML(question, html);
        return true;
      }
    }

  private:
    OJ::Model _model;
    OJ::View _view;
  };
}